package model

import "time"

type EventLevel uint8

const (
	LevelDebug EventLevel = iota
	LevelInfo
	LevelWarning
	LevelError
)

func (e EventLevel) String() string {
	switch e {
	case LevelDebug:
		return "debug"
	case LevelInfo:
		return "info"
	case LevelWarning:
		return "warning"
	case LevelError:
		return "error"
	default:
		return "unknownLevel"
	}
}

func (e *EventLevel) Scan(src interface{}) error {
	v := src.(int64)
	*e = EventLevel(v)
	return nil
}

// 检查一个level，当传入的level大于或等于自身时返回true
func (e EventLevel) Check(other EventLevel) bool {
	return uint8(other) >= uint8(e)
}

type Event struct {
	Level   EventLevel `gorm:"type:int;not null"`    // 消息等级
	Message string      `gorm:"size:256"`             // 消息内容
	MoonID  string      `gorm:"size:40;index:moon"`   // 节点ID
	Source  string      `gorm:"size:40;index:source"` // 消息来源
	Time    time.Time
}
